#include "ExtentStatsAlgo.h"


ExtentStatsAlgo::ExtentStatsAlgo(Extent* extent)
{
	ex = extent;
	stats = new vector<ExtentStatistics*>();
	totalRM = 0.0;
	currentSlice=true;
}

ExtentStatsAlgo::~ExtentStatsAlgo(void)
{
}

void ExtentStatsAlgo::deleteContent(){
	vector<ExtentStatistics*>::iterator iter;
	for (iter = stats->begin(); iter != stats->end(); iter++){
		delete (*iter);
	}
	delete stats;
}

void ExtentStatsAlgo::deleteStat(){
	vector<ExtentStatistics*>::iterator iter;
	if (stats->size()>1)
		cout<<"problem - more then one statistics!"<<endl;
	iter = stats->begin();
	delete (*iter);
	stats->erase(iter);
}

void ExtentStatsAlgo::multiplyG(double g, int currentTime){
	for (int i=0; i<(int)stats->size(); i++){
		if (stats->at(i)->getTime()!=currentTime)
			stats->at(i)->multiplyStats(g);
	}
	calculateTotalRM();
}

void ExtentStatsAlgo::calculateTotalRM(){
	totalRM = 0;
	for (int i=0; i<stats->size(); i++)
		totalRM+=stats->at(i)->getStat(rand_rm);
}

void ExtentStatsAlgo::removeStatsOfTime(int timeToDelete){
	vector<ExtentStatistics*>::iterator itStats;
	for (itStats = stats->begin(); itStats != stats->end();){
		if (((*itStats)->getTime() == timeToDelete)){
			delete (*itStats);
			itStats = stats->erase(itStats);
			break;
		}
		else{
			itStats++;
		}
	}
	calculateTotalRM();
}

void ExtentStatsAlgo::addStat(ExtentStatistics* stat){
	stats->push_back(stat);
}

ExtentStatistics* ExtentStatsAlgo::getStat(int time){
	vector<ExtentStatistics*>::iterator itStats;
	if (stats){
		for(itStats = stats->begin(); itStats != stats->end(); itStats++){
			if ((*itStats)->getTime() == time)
				return *itStats;
		}
	}
	return 0;
}

void ExtentStatsAlgo::addTotalRM(double s){
	totalRM+=s;
}

void ExtentStatsAlgo::multiplyGInfinite(double g){
	totalRM=totalRM*g;
}

